<template>
    <div>
        <div class="content">
            <div class="content-box">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input id="title" type="text" value="" name="title" placeholder="请输入标题" autocomplete="off" class="
layui-input title" v-model="title">
                            </div>
                        </div>
                    <div class="layui-form-item ask-type">
                        <div class="layui-input-block">
                            <input id="type" value="" cid="" type="text" name="type" placeholder="标签,如:linkphp" autocomplete="off" class="
layui-input tags" v-model="type">
                            <div class="ask-type-down">
                                <div class="ask-type-box">
                                    </div>
                                </div>
                            </div>
                        </div>
                    <div class="layui-form-item layui-form-text ask-dec">
                        <div id="markdown">
                            <textarea id="desc" name="desc" style="display: none;" v-model="desc"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        <div class="footerbtn" style="z-index:9999;">
        <a id="saveFun" class="layui-btn layui-btn" v-on:click="push"><i class="layui-icon">&#xe619;</i> 发布</a>
        <a id="btnRefresh" class="layui-btn layui-btn-normal layui-btn"><i class="layui-icon">&#x1002;</i>刷新</a>
        <a id="closeFun" class="layui-btn layui-btn layui-btn-danger"><i class="layui-icon">&#x1006;</i> 放弃</a>
        </div>
    </div>
</template>

<script>
import { tagAsk } from '../event/ask.js'
import request from '../link/request.js'
export default {
  name: 'Ask',
  data () {
    return {
      title: '',
      type: '',
      content: ''
    }
  },
  mounted () {
    let self = this
    self.isLogin(function (res) {
      if (res.code === 2) {
        self.redirect('login')
        return false
      }
    })
    tagAsk()
    this.markdown()
  },
  methods: {
    markdown () {
      editormd ("markdown", {
        width   : "99.5%",
        height  : 380,
        syncScrolling : "single",
        path    : "/static/editor.md/lib/"
      })
    },
    push (res) {
      let that = this
      console.log(this.desc)
      request.post('/index.php/main/forum/push', {
        title: this.title,
        desc: $('#desc').val()
      })
        .then(function (response) {
          console.log(response)
          if (response.code === 1) {
            layer.msg(response.msg, {icon: response.code})
            setTimeout(that.redirect('forum'), 5000)
          } else {
            layer.msg(response.msg, {icon: response.code})
          }
        })
    }
  }
}
</script>

<style src="../assets/css/ask.css" scoped></style>
<style src="../assets/css/form.css" scoped></style>
